package com.zmn.oms.common.constant;

import com.google.common.collect.Lists;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.common.dto.ResultDTO;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName VerifyOrderConsts
 * @description:
 * @author: wangyanci
 * @create: 2021-07-23 16:26
 * @Version 1.0
 **/
public class VerifyOrderConsts {

    // 分单撤回编码 100
    // 派单撤回编码 101

    // 分单撤回-服务区域不满足
    public static final int ASSIGNBACK_SERVER_AREA = 1001;

    // 分单撤回-服务产品不满足
    public static final int ASSIGNBACK_SERVER_PRODUCT = 1002;

    // 分单撤回-未开通对应业务类型
    public static final int ASSIGNBACK_NOT_OPEN_BUSINESS = 1003;

    // 分单撤回-尾款限制不满足
    public static final int ASSIGNBACK_BALANCE_PAYMENT_LIMIT = 1004;





    // 派单撤回-工程师已达最大手头返修单
    public static final int DISTRIBUTEBACK_MASTER_ORDER_MAXIMUM = 1011;

    // 派单撤回-工程师服务返回
    public static final int DISTRIBUTEBACK_MASTER_ORDER_MASTER_SERVICE = 1012;

    // 派单撤回-工程师城市不符合
    public static final int DISTRIBUTEBACK_MASTER_SERVICE_CITY = 1013;

    // 派单撤回-行政子公司变更
    public static final int DISTRIBUTEBACK_MASTER_GRID_COMPANY = 1014;


    // 分单撤回集合
    public static final List<Integer> ASSIGNBACKLIST = Lists.newArrayList(
            ASSIGNBACK_SERVER_AREA,
            ASSIGNBACK_SERVER_PRODUCT,
            ASSIGNBACK_NOT_OPEN_BUSINESS,
            ASSIGNBACK_BALANCE_PAYMENT_LIMIT
    );

    // 派单撤回集合
    public static final List<Integer> DISTRIBUTEBACKLIST = Lists.newArrayList(
            DISTRIBUTEBACK_MASTER_ORDER_MAXIMUM,
            DISTRIBUTEBACK_MASTER_ORDER_MASTER_SERVICE,
            DISTRIBUTEBACK_MASTER_SERVICE_CITY,
            DISTRIBUTEBACK_MASTER_GRID_COMPANY
    );


    public static String getMessage(ResultDTO resultDTO){
        if (Objects.isNull(resultDTO)) {
            return null;
        }
        if (!resultDTO.isStatusBool()) {
            return null;
        }

        String message = VerifyOrderConsts.backSwitch(resultDTO);

        if (StringUtil.isBlank(message)) {
            return null;
        }

        if (ASSIGNBACKLIST.contains(resultDTO.getStatus())) {
            return String.format("%s%s", message, "会导致分单撤回");
        } else if (DISTRIBUTEBACKLIST.contains(resultDTO.getStatus())) {
            return String.format("%s%s", message, "会导致派单撤回");
        }

        return null;
    }

    public static String backSwitch(ResultDTO resultDTO){
        switch (resultDTO.getStatus()) {
            case ASSIGNBACK_SERVER_AREA:
                return "服务区域不满足/服务产品不满足/业务类型不匹配";
            case ASSIGNBACK_SERVER_PRODUCT:
                return "服务产品不满足";
            case ASSIGNBACK_NOT_OPEN_BUSINESS:
                return "未开通对应业务类型";
            case ASSIGNBACK_BALANCE_PAYMENT_LIMIT:
                return "尾款限制不满足";
            case DISTRIBUTEBACK_MASTER_SERVICE_CITY:
                return "工程师城市不符合";
            case DISTRIBUTEBACK_MASTER_ORDER_MAXIMUM:
                return "工程师已达最大手头返修单";
            case DISTRIBUTEBACK_MASTER_GRID_COMPANY:
                return "行政子公司发生变更";
            case DISTRIBUTEBACK_MASTER_ORDER_MASTER_SERVICE:
                return resultDTO.getData().toString().replaceAll("，不可派单", "");
            default:
                return null;
        }
    }
}